package com.matrix.lbs.listener;

import com.matrix.api.lbs.dto.ShopInfoUpdateDTO;
import com.matrix.common.constant.RocketMQConstants;
import com.matrix.lbs.service.LbsService;
import lombok.RequiredArgsConstructor;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * @author 有点甜
 * @since 2025/7/30
 */
@Component
@RequiredArgsConstructor
@RocketMQMessageListener(topic = RocketMQConstants.SHOP_INFO_UPDATE_TOPIC,
        consumerGroup = RocketMQConstants.SHOP_INFO_UPDATE_CONSUMER_GROUP)
public class ShopInfoUpdateListener implements RocketMQListener<ShopInfoUpdateDTO> {
    private final LbsService lbsService;

    @Override
    public void onMessage(ShopInfoUpdateDTO dto) {
        try {
            lbsService.upsertShopDocument(dto);
        } catch (Exception e) {
            throw new RuntimeException("Failed to update shop document in ES", e);
        }
    }
}
